#!/usr/bin/python
#!encoding: utf-8

import os
import sys
import stat
from untils.untils import log
from routes.server.tool import Sync_Remote
import threading
from routes.server.time_check import server_check_time


def ntp_sync(server, ntp_server, timeZone):

    try:
        remote = Sync_Remote(server)
        remote.time_sync_from(ntp_server, timeZone)
        remote.close()
        log('ntp_sync {} done!'.format(server.ip))
        server_check_time(server)
    except Exception as e:
        log('ntp_sync {} error : {}'.format(server.ip, e), level='error')


def ntp_sync_all(servers, ntp_server, timeZone):
    def f(servers, ntp_server, timeZone):
        for s in servers:
            log('ntp_sync_all:',(s, ntp_server, timeZone), level='debug')
            ntp_sync(s, ntp_server, timeZone)
    # t = threading.Thread(target=f, args=(servers, ntp_server, timeZone))
    # t.start()
    f(servers, ntp_server, timeZone)

if __name__ == '__main__' :
    server = []
